<%@ page pageEncoding="UTF-8"%>
<%@ include file="../commons/head.jsp"%>
<title>JS的AJAX</title>
<style>
table, tr, td {
        		border: 1px solid #000;
        		border-collapse: collapse;
        	}
        	table {
        		width: 400px;
        	}
        	td {
        		height: 25px;
        	}
</style>
</head>
<body>
<div>
<input type="button" onclick="union();" value="union连接" id="getUnion">
	<table>
		<thead>
			<tr>
				<th>序号</th>
				<th>账户</th>
				<th>姓名</th>
			</tr>
		</thead>
		<tbody>
		
		</tbody>
	</table>
<input type="button" onclick="unionAll();" value="unionAll连接" id="getUnionAll">
	<table>
		<thead>
			<tr>
				<th>序号</th>
				<th>账户</th>
				<th>姓名</th>
			</tr>
		</thead>
		<tbody>
		
		</tbody>
	</table>
<!-- <input type="button" onclick="crossjoin();" value="逗号连接" id="crossjoin">
	<table>
		<thead>
			<tr>
				<th>序号</th>
				<th>账户</th>
				<th>姓名</th>
			</tr>
		</thead>
		<tbody>
		
		</tbody>
	</table> -->
<input type="button" onclick="ziSearch();" value="子查询" id="ziSearch">
	<table>
		<thead>
			<tr>
				<th>序号</th>
				<th>账户</th>
				<th>姓名</th>
			</tr>
		</thead>
		<tbody>
		
		</tbody>
	</table>
</div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<script type="text/javascript">
function union(){
	$.ajax({
		url:"${pageContext.request.contextPath}/huangyan/union",
		contentType: "application/json; charset=utf-8",
		method:'',
		data:{},
		dataType:'json',
		complate:  function(XMLHttpRequest){
			alert("准备就绪");
		},
		success:function(data){debugger
			//var list = data.rows;
    		
			for(var i=0;i<data.length;i++){
				var newtr=document.createElement("tr");
	    		
	    		var td1=document.createElement("td");
	    		td1.innerText=data[i].id;
	    		var td2=document.createElement("td");
	    		td2.innerText=data[i].userAccount;
	    		var td3=document.createElement("td");
	    		td3.innerText=data[i].userName;
	    		newtr.appendChild(td1);
	    		newtr.appendChild(td2);
	    		newtr.appendChild(td3);
	    		
	    		var tb=document.getElementsByTagName("tbody").item(0);
	    		tb.insertBefore(newtr,tb.firstElementChild);
	    		
	    		$("#getUnion").attr("disabled",true)
			} 
		},
		error:function(XMLHttpRequest, textStatus, errorThrown){
			alert("出错了");
		}
	});
}
function unionAll(){
	$.ajax({
		url:"${pageContext.request.contextPath}/huangyan/unionAll",
		contentType: "application/json; charset=utf-8",
		method:'',
		data:{},
		dataType:'json',
		complate:  function(XMLHttpRequest){
			alert("准备就绪");
		},
		success:function(data){debugger
			//var list = data.rows;
    		
			for(var i=0;i<data.length;i++){
				var newtr=document.createElement("tr");
	    		
	    		var td1=document.createElement("td");
	    		td1.innerText=data[i].id;
	    		var td2=document.createElement("td");
	    		td2.innerText=data[i].userAccount;
	    		var td3=document.createElement("td");
	    		td3.innerText=data[i].userName;
	    		newtr.appendChild(td1);
	    		newtr.appendChild(td2);
	    		newtr.appendChild(td3);
	    		
	    		var tb=document.getElementsByTagName("tbody").item(1);
	    		tb.insertBefore(newtr,tb.firstElementChild);
	    		
	    		$("#getUnionAll").attr("disabled",true)
			} 
		},
		error:function(XMLHttpRequest, textStatus, errorThrown){
			alert("出错了");
		}
	});
}
function crossjoin(){
	$.ajax({
		url:"${pageContext.request.contextPath}/huangyan/crossjoin",
		contentType: "application/json; charset=utf-8",
		method:'',
		data:{},
		dataType:'json',
		complate:  function(XMLHttpRequest){
			alert("准备就绪");
		},
		success:function(data){debugger
			//var list = data.rows;
    		
			for(var i=0;i<data.length;i++){
				var newtr=document.createElement("tr");
	    		
	    		var td1=document.createElement("td");
	    		td1.innerText=data[i].id;
	    		var td2=document.createElement("td");
	    		td2.innerText=data[i].userAccount;
	    		var td3=document.createElement("td");
	    		td3.innerText=data[i].userName;
	    		newtr.appendChild(td1);
	    		newtr.appendChild(td2);
	    		newtr.appendChild(td3);
	    		
	    		var tb=document.getElementsByTagName("tbody").item(2);
	    		tb.insertBefore(newtr,tb.firstElementChild);
	    		
	    		$("#crossjoin").attr("disabled",true)
			} 
		},
		error:function(XMLHttpRequest, textStatus, errorThrown){
			alert("出错了");
		}
	});
}
function ziSearch(){
	$.ajax({
		url:"${pageContext.request.contextPath}/huangyan/ziSearch",
		contentType: "application/json; charset=utf-8",
		method:'',
		data:{},
		dataType:'json',
		complate:  function(XMLHttpRequest){
			alert("准备就绪");
		},
		success:function(data){debugger
			//var list = data.rows;
    		
			for(var i=0;i<data.length;i++){
				var newtr=document.createElement("tr");
	    		
	    		var td1=document.createElement("td");
	    		td1.innerText=data[i].id;
	    		var td2=document.createElement("td");
	    		td2.innerText=data[i].userAccount;
	    		var td3=document.createElement("td");
	    		td3.innerText=data[i].userName;
	    		newtr.appendChild(td1);
	    		newtr.appendChild(td2);
	    		newtr.appendChild(td3);
	    		
	    		var tb=document.getElementsByTagName("tbody").item(2);
	    		tb.insertBefore(newtr,tb.firstElementChild);
	    		
	    		$("#ziSearch").attr("disabled",true)
			} 
		},
		error:function(XMLHttpRequest, textStatus, errorThrown){
			alert("出错了");
		}
	});
}

</script>
</body>
</html>